package com.qax.task.cron.support;

import com.qax.task.cron.TriggerContext;

import java.util.Date;

/**
 * <BR>Simple execution time context, used to get the next execution time and interval time<BR/>
 * {@link TriggerContext#lastScheduledExecutionTime}
 * {@link TriggerContext#lastActualExecutionTime}
 * {@link TriggerContext#lastCompletionTime}
 *
 *
 *
 * @author leiliang
 */
public class SimpleTriggerContext implements TriggerContext {
    /**
     * 最后一次计划执行时间
     */
    private volatile Date lastScheduledExecutionTime;
    /**
     * 上一次真实执行时间
     */
    private volatile Date lastActualExecutionTime;
    /**
     * 上一次完成时间
     */
    private volatile Date lastCompletionTime;


    /**
     * Create a SimpleTriggerContext with all time values set to {@code null}.
     */
    public SimpleTriggerContext() {
    }

    /**
     * Create a SimpleTriggerContext with the given time values.
     * @param lastScheduledExecutionTime last <i>scheduled</i> execution time
     * @param lastActualExecutionTime last <i>actual</i> execution time
     * @param lastCompletionTime last completion time
     */
    public SimpleTriggerContext(Date lastScheduledExecutionTime, Date lastActualExecutionTime, Date lastCompletionTime) {
        this.lastScheduledExecutionTime = lastScheduledExecutionTime;
        this.lastActualExecutionTime = lastActualExecutionTime;
        this.lastCompletionTime = lastCompletionTime;
    }


    /**
     * Update this holder's state with the latest time values.
     * @param lastScheduledExecutionTime last <i>scheduled</i> execution time
     * @param lastActualExecutionTime last <i>actual</i> execution time
     * @param lastCompletionTime last completion time
     */
    public void update(Date lastScheduledExecutionTime, Date lastActualExecutionTime, Date lastCompletionTime) {
        this.lastScheduledExecutionTime = lastScheduledExecutionTime;
        this.lastActualExecutionTime = lastActualExecutionTime;
        this.lastCompletionTime = lastCompletionTime;
    }


    @Override
    public Date lastScheduledExecutionTime() {
        return this.lastScheduledExecutionTime;
    }

    @Override
    public Date lastActualExecutionTime() {
        return this.lastActualExecutionTime;
    }

    @Override
    public Date lastCompletionTime() {
        return this.lastCompletionTime;
    }
}
